<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2019/5/21
 * Time: 13:23
 */
namespace app\admin\model;
class Functions
{
    static public function getDirList($path=null,$array=[]){
        $dir = '';
        if($path){
            $dir = scandir($path);
        }
        $data = [];
        foreach ($dir as $value){
            if($value!=='.'&&$value!=='..'){
                if(is_dir(rtrim($path,'/').'/'.$value)){
                    if(!in_array($value,$array)){
                        $data[] = $value;
                    }
                }
            }
        }
        return $data;
    }
    static function changeConfig($filename,$data){
        $str = '<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2019/5/21
 * Time: 13:02
 */
return ['.PHP_EOL;
        foreach ($data as $value){
            $str .='['.PHP_EOL;
            foreach ($value as $key=>$v){
                if($key==count($value)-1){
                    $str.= '"'.$key.'"=>"'.$v.'"'.PHP_EOL;
                }else{
                    $str.= '"'.$key.'"=>"'.$v.'",'.PHP_EOL;
                }
            }
            $str .='],'.PHP_EOL;
        }
$str.='];'.PHP_EOL;
//        chmod($filename,0777);
        $bool = file_put_contents($filename,$str);
        return $bool;
    }
}